home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_c / cuj0696.zip / DWYER.ZIP / QFLOAT / QFLOATEX.H < prev    next >
C/C++ Source or Header  |  1996-03-10  |  3KB  |  160 lines

  1. #include "qhead.h"
  2. struct qfloatstruct
  3.   {
  4.     QELT ar[NQ];
  5. //    unsigned short ar[24];
  6.   };
  7.  
  8. extern "C"
  9. {
  10.   void qclear (qfloatstruct *);
  11.   void etoq (const double *, qfloatstruct *);
  12.   void e64toq (const long double *, qfloatstruct *);
  13.   void ltoq (long int *, qfloatstruct *);
  14.   void asctoq (const char *, qfloatstruct *);
  15. }
  16.  
  17. class qfloat
  18. {
  19.   public:
  20.   struct qfloatstruct a;
  21.   qfloat () {qclear(&a);};
  22.   qfloat (double x) {etoq (&x, &a);}
  23.   qfloat (long double x) {e64toq (&x, &a);}
  24.   qfloat (long int x) {ltoq (&x, &a);}
  25. // For conversion and assignment x = "1.234e4321"
  26.   qfloat (char *x) {asctoq (x, &a);}
  27.   friend long qtol (qfloat);
  28.   friend float qtof (qfloat);
  29.   friend double qtod (qfloat);
  30.   friend long double qtold (qfloat);
  31. };
  32.  
  33. extern "C"
  34. {
  35.   void qadd (const qfloat &, const qfloat &, qfloat &);
  36.   void qsub (const qfloat &, const qfloat &, qfloat &);
  37.   void qmul (const qfloat &, const qfloat &, qfloat &);
  38.   void qdiv (const qfloat &, const qfloat &, qfloat &);
  39.   void qtoasc (const qfloat *, char *, const int);
  40.   void qtoe (const qfloat *, double *);
  41.   void qtoe64 (const qfloat *, long double *);
  42.   void qifrac (const qfloat *, long *, qfloat *);
  43.   int qcmp (const qfloat &, const qfloat &);
  44.   int mtherr (char *, int);
  45.   void qexp (const qfloat *, qfloat *);
  46.   void qabs (qfloat *);
  47.   void qneg (qfloat *);
  48. }
  49.  
  50. inline long qtol (qfloat x) {qfloat y; long l; qifrac(&x, &l, &y); return l;}
  51.  
  52. inline double qtod (qfloat x) {double d; qtoe(&x, &d); return d;}
  53.  
  54. inline long double qtold (qfloat x) {long double d; qtoe64(&x, &d); return
  55. d;}
  56.  
  57.  
  58. inline qfloat operator + (const qfloat & x, const qfloat & y)
  59. {
  60.   qfloat z;
  61.   qadd (x, y, z);
  62.   return z;
  63. }
  64.  
  65. inline void operator += (qfloat & x, const qfloat & y)
  66. {
  67.   qadd (x, y, x);
  68. }
  69.  
  70. inline qfloat operator - (const qfloat & x, const qfloat & y)
  71. {
  72.   qfloat z;
  73.   qsub (y, x, z);
  74.   return z;
  75. }
  76.  
  77. /* Unary negation. */
  78. inline qfloat operator - (qfloat x)
  79. {
  80.   qfloat z;
  81.   z = x;
  82.   qneg (&z);
  83.   return z;
  84. }
  85.  
  86. inline void operator -= (qfloat & x, const qfloat & y)
  87. {
  88.   qsub (y, x, x);
  89. }
  90.  
  91. inline qfloat operator * (const qfloat & x, const qfloat & y)
  92. {
  93.   qfloat z;
  94.   qmul (x, y, z);
  95.   return z;
  96. }
  97.  
  98. inline void operator *= (qfloat & x, const qfloat & y)
  99. {
  100.   qmul (y, x, x);
  101. }
  102.  
  103. inline qfloat operator / (const qfloat & x, const qfloat & y)
  104. {
  105.   qfloat z;
  106.   qdiv (y, x, z);
  107.   return z;
  108. }
  109.  
  110. inline void operator /= (qfloat & x, const qfloat & y)
  111. {
  112.   qdiv (y, x, x);
  113. }
  114.  
  115. inline int operator == (const qfloat & x, const qfloat & y)
  116. {
  117.   return (qcmp (x, y) == 0);
  118. }
  119.  
  120. inline int operator != (const qfloat & x, const qfloat & y)
  121. {
  122.   return (qcmp (x, y) != 0);
  123. }
  124.  
  125. inline int operator < (const qfloat & x, const qfloat & y)
  126. {
  127.   return (qcmp (x, y) == -1);
  128. }
  129.  
  130. inline int operator > (const qfloat & x, const qfloat & y)
  131. {
  132.   return (qcmp (x, y) == 1);
  133. }
  134.  
  135. inline int operator >= (const qfloat & x, const qfloat & y)
  136. {
  137.   return (qcmp (x, y) >= 0);
  138. }
  139.  
  140. inline int operator <= (const qfloat & x, const qfloat & y)
  141. {
  142.   return (qcmp (x, y) <= 0);
  143. }
  144.  
  145. // Define other function calls analogously.
  146. inline qfloat exp (qfloat x)
  147. {
  148.   qfloat y;
  149.   qexp (&x, &y);
  150.   return y;
  151. }
  152.  
  153. inline qfloat abs (qfloat x)
  154. {
  155.   qfloat y;
  156.   y = x;
  157.   qabs (&y);
  158.   return y;
  159. }
  160.